package com.sky.mapper;

import com.sky.aop.AutoFill;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.entity.SetmealDish;
import com.sky.enumeration.OperationType;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface SetmealMapper {

    /**
     * 根据分类id查询套餐的数量
     * @param id
     * @return
     */
    @Select("select count(id) from setmeal where category_id = #{categoryId}")
    Integer countByCategoryId(Long id);

    /**
     * 新增套餐信息
     * @param setmeal
     */
    @Insert("insert into setmeal values (null, #{categoryId}, #{name}, #{price}, " +
            "#{status}, #{description}, #{image}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser})")
    // 新增后返回主键
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @AutoFill(OperationType.INSERT)
    void insertSetmeal(Setmeal setmeal);

    /**
     * 套餐分页查询
     * @param setmealPageQueryDTO
     * @return
     */
    List<SetmealVO> selectSetmeal(SetmealPageQueryDTO setmealPageQueryDTO);

    /**
     * 根据id查询菜品信息
     * @param id
     * @return
     */
    @Select("select * from setmeal where id = #{id}")
    Setmeal selectSetmealById(Long id);

    /**
     * 修改套餐基本信息
     * @param setmeal
     */
    @AutoFill(OperationType.UPDATE)
    void updateSetmeal(Setmeal setmeal);

    /**
     * 删除套餐
     * @param ids
     */
    void deleteSetmealByIds(@Param("ids") List<Long> ids);

    /**
     * 按条件查询套餐
     * @param setmeal
     * @return
     */
    List<Setmeal> selectSetmealByCategoryId(Setmeal setmeal);

    /**
     * 查询当前套餐的启售停售数量
     * @param map
     * @return
     */
    Integer selectCountByMap(Map map);
}
